package com.city.service.supervise.impl;

import com.city.domain.supervise.ImpCategory;
import com.city.repository.supervise.ImpCategoryRepository;
import com.city.service.supervise.ImpCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Xln_z
 * @date: 2018/8/24
 * @decription:
 **/
@Service
public class ImpCategoryServiceImpl implements ImpCategoryService {

    @Autowired
    private ImpCategoryRepository impCategoryRepository;

    @Override
    public List<ImpCategory> getImpCategoryLimit(Integer limitPage, Integer limitNum){
        return impCategoryRepository.getImpCategoryLimit((limitPage - 1) * limitNum, limitNum);
    }

    @Override
    public List<ImpCategory> getImpCategoryLimit(Integer limitPage, Integer limitNum, String search){
        return impCategoryRepository.getImpCategoryLimit((limitPage - 1) * limitNum, limitNum, search);
    }


    @Override
    public List<ImpCategory> findAll(ImpCategory impCategory){
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withMatcher("event_name", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("maname", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("tellphone", ExampleMatcher.GenericPropertyMatchers.contains()); //“模糊查询”的方式查询

        //创建实例
        Example<ImpCategory> ex = Example.of(impCategory, matcher);

        //查询
        return impCategoryRepository.findAll(ex);
    }

    @Override
    public Long count(ImpCategory impCategory){
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withMatcher("event_name", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("maname", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("tellphone", ExampleMatcher.GenericPropertyMatchers.contains());


        //创建实例
        Example<ImpCategory> ex = Example.of(impCategory, matcher);

        //查询
        return impCategoryRepository.count(ex);
    }

}
